package com.gemme.gemme;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.gemme.gemme.home.ProductListActivity;
import com.gemme.gemme.view.GeAddressButton;
import com.gemme.gemme.view.Topview;
import com.gemme.gemme.wode.AddAddressActivity;
import com.jaeger.library.StatusBarUtil;
import com.yanzhenjie.recyclerview.SwipeRecyclerView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;


//侧滑删除地址
public class SearchActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search);
        //hdlsajkdasl
        initView();

    }

    private void initView() {
        View cancel = findViewById(R.id.cancel);
       /* cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(mContext, ProductListActivity.class));
            }
        });*/

        SwipeRecyclerView recycler_view = findViewById(R.id.recycler_view);

        LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
        recycler_view.setLayoutManager(mLayoutManager);
//        recycler_view.setAdapter(new SearchAdapter());

       EditText et_search= findViewById(R.id.et_search);
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               /* Intent intent = new Intent(mContext, ProductListActivity.class);
                intent.putExtra("keyWork",et_search.getText() + "");
                startActivity(intent);*/
               finish();
            }
        });


        et_search.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_DONE) {
                    System.out.println("");
                    Intent intent = new Intent(mContext, ProductListActivity.class);
                    intent.putExtra("keyWork",et_search.getText() + "");
                    startActivity(intent);
                }
                return false;
            }
        });


    }
   class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.ViewHolder>{

       @NonNull
       @Override
       public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
           View inflate = LayoutInflater.from(parent.getContext()).
                   inflate(R.layout.search_item, null);
           LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
           inflate.setLayoutParams(layoutParams);
           return new SearchAdapter.ViewHolder(inflate);
       }

       @Override
       public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
           holder.itemView.setOnClickListener(new View.OnClickListener() {
               @Override
               public void onClick(View view) {
                   Intent intent = new Intent(mContext, ProductListActivity.class);
                   intent.putExtra("keyWork","口红");
                   startActivity(intent);
               }
           });
       }

       @Override
       public int getItemCount() {
           return 4;
       }

       public class ViewHolder extends RecyclerView.ViewHolder {
           public ViewHolder(@NonNull View itemView) {
               super(itemView);
           }
       }
   }

}